package com.yxjx.duoxue.mta.stat;

import java.util.HashMap;
import java.util.Properties;

import com.tencent.stat.StatService;
import com.yxjx.duoxue.utils.Utils;

import android.content.Context;
import android.util.Property;

/**
 * 腾讯MTA统计
 * @author mengmengchen
 *
 */
public class StatHelper {

	public static final String KEY_CHANNEL = "channel";
	public static final String KEY_DEVICE = "device";
	public static final String KEY_SCHOOL = "school";
	public static final String KEY_COURSE = "course";
	public static final String KEY_ACTIVITY = "act";
	public static final String KEY_TEACHER = "teacher";
	public static final String KEY_PHONE = "phone";
	public static final String KEY_SORT_BY = "type";
	public static final String KEY_AD = "ad";
	public static final String KEY_KEYWORD = "keyword";
	
	// 通用参数
	
	/**
	 * reuse when stat MTA
	 * @param context
	 * @return
	 */
	public static Properties getBasicProp(Context context) {
		Properties prop = new Properties();
		prop.put(StatHelper.KEY_CHANNEL, Utils.getChannelCode(context));
		prop.put(StatHelper.KEY_PHONE, Utils.getPhoneNum(context));
		prop.put(StatHelper.KEY_DEVICE, Utils.getShortDeviceId(context));
		return prop;
	}
	
	/**
	 * add MTA kv event, args for extra kv values.
	 * @param context
	 * @param event_name
	 * @param args
	 */
	public static void addKVEvent(Context context, String event_name, Object... args) {
		if (context == null) {
			return;
		}
		
		Properties prop = StatHelper.getBasicProp(context);
		if (args != null && args.length > 0 && (args.length % 2 == 0)) {
			for (int i = 0; i < (args.length / 2); i++) {
				prop.put(args[i*2], args[i*2 +1]);
			}
		}
		StatService.trackCustomKVEvent(context, event_name, prop);
	}
}
